package edu.sctu.java.advanced.filter;

import java.util.ArrayList;
import java.util.List;

public class FilterChain {
    List<Filter> filters;
    int pos;

    public FilterChain() {
        this.pos = 0;
        this.filters = new ArrayList<>();
    }

    void addFilter(Filter filter) {
        this.filters.add(filter);
    }

    void doInternalFilter(Request request, Response response) {

        if (pos < filters.size()) {

            Filter filter = this.filters.get(pos++);
            filter.doFilter(request, response, this);
        }

    }
}
